package org.xwb.springcloud.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xwb.springcloud.messagetype.ack.AckProducer;
import org.xwb.springcloud.messagetype.deadletter.DeadLetterProducer;
import org.xwb.springcloud.messagetype.direct.DirectProducer;
import org.xwb.springcloud.messagetype.fanout.FanoutProducer;
import org.xwb.springcloud.messagetype.simple.SimpleProducer;
import org.xwb.springcloud.messagetype.topic.TopicQueueProducer;
import org.xwb.springcloud.messagetype.workqueue.WorkQueueProducer;

import javax.annotation.Resource;

/**
 * @author 10564
 */
@RestController
@RequestMapping("/mq")
public class MqMessageController {

    @Resource
    private WorkQueueProducer workQueueProducer;

    @Resource
    private SimpleProducer simpleProducer;

    @Resource
    private FanoutProducer fanoutProducer;

    @Resource
    private DirectProducer directProducer;

    @Resource
    private TopicQueueProducer topicQueueProducer;

    @Resource
    private DeadLetterProducer deadLetterProducer;

    @Resource
    private AckProducer ackProducer;

    @GetMapping("/workQueue")
    public void workQueueTest(String message) {
        workQueueProducer.senderWorkQueueMessage("workQueue " + message);
    }

    @GetMapping("/simple")
    public void simpleProducerTest(String message) {
        simpleProducer.senderSimple(message);
    }

    @GetMapping("/fanout")
    public void fanoutProducerTest(String message) {
        fanoutProducer.senderFanoutQueue("fanout " + message);
    }

    @GetMapping("/direct")
    public void directProducerTest(String message) {
        directProducer.senderDirectOneMessage("direct one " + message);
        directProducer.senderDirectTwoMessage("direct two " + message);
    }

    @GetMapping("/topic")
    public void topicQueueProducerTest(String message, String routingKey) {
        topicQueueProducer.senderTopicQueueRoutingMatching("topic one " + message, routingKey);
    }

    @GetMapping("/deadLetter")
    public void deadLetter(String message) {
        deadLetterProducer.senderDeadLetterMessage(message);
    }
    @GetMapping("/ack")
    public void ack(String message) {
        ackProducer.senderAckMessage(message);
    }
}
